perm filename PUPHST.NEW[HST,NET] blob sn#727527 filedate 1983-09-10 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00007 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	TITLE PUPHST  A B C H X P ICH OCH PDLEN BUFNUM
C00004 00003	Data area  PDL OBUFH PUPBLK HSTBLK PUPDIR NUMNAM NAMLKP NUMADR ADRLKP NUMENT FSTENT PUPVRS HDRDIZ ENTPTR
C00006 00004	Useful subroutines  CPOPJ1 CPOPJ PUTCH OUTCH1 PUTSTR PUTST1 PUTDEC PUTOCT PUTOC1 PUTSIX PUTDAT MONTH ERROR
C00009 00005	More subroutines  OUTADR OUTNAM OUTNLP COMPAR COMPLP COMPL1 COMPL2 CMPLUZ PUTATR PUTALP PUTAT1
C00015 00006	Initialization  PUPHST
C00017 00007	Main loop  PUPIN HDRLP MAINLP ALLDUN
C00022 ENDMK
C⊗;
TITLE PUPHST ;⊗ A B C H X P ICH OCH PDLEN BUFNUM

SUBTTL Program to convert PUP directory to RFC810 format

COMMENT ⊗

This program reads in the binary form of the PUP Network directory, and
outputs a text file as specified in RFC810 with the same information.  This
is intended to be merged with the NIC host table by the HOSTS3 program.

For a desription of the format of the PUP directory, see the file
<PUP>PupDirectory.press on the IFS.

History (please record changes)

 5 Jun 83 JJW	Initial implementation
10 Sep 83 JJW	Output IP addresses as well as Ethernet addresses.
		FTETHB switch determines form of IP addresses.

⊗	;end of comment

IFNDEF FTETHB,<FTETHB←←0>	;Non-zero for class B SU-NET

;AC definitions
A←1
B←2
C←3
D←4
E←5
H←10
X←11
P←17

;I/O channels
ICH←←0
OCH←←1

PDLEN←←20
BUFNUM←←=19			;Recommended number of disk buffers
;Data area ;⊗ PDL OBUFH PUPBLK HSTBLK PUPDIR NUMNAM NAMLKP NUMADR ADRLKP NUMENT FSTENT PUPVRS HDRDIZ ENTPTR

PDL:	BLOCK PDLEN

OBUFH:	BLOCK 3			;Output buffer header
DMPNAM:	BLOCK 1			;Name of the DMP file we come from

PUPBLK:	SIXBIT/PUPNET/		;Lookup block for input file
	SIXBIT/DIR/
	0
	SIXBIT/HSTNET/

HSTBLK:	SIXBIT/PUPHST/		;Enter block for output file
	SIXBIT/TXT/
	0
	SIXBIT/HSTNET/

PUPDIR:	BLOCK 1			;Address of PUP directory read in

;Data from header block in PUP directory.  All blocks and tables are guaranteed
;to be on an even 16-bit byte boundary, i.e., at the start of a PDP-10 word.
NUMNAM:	BLOCK 1			;Number of name blocks
NAMLKP:	BLOCK 1			;Pointer to name lookup table
NUMADR:	BLOCK 1			;Number of address blocks
ADRLKP:	BLOCK 1			;Pointer to address lookup table
NUMENT:	BLOCK 1			;Number of 16-bit words occupied by entry blocks
FSTENT:	BLOCK 1			;Pointer to first entry block
PUPVRS:	BLOCK 1			;Version of PUP directory
HDRSIZ←←.-NUMNAM		;Size of header block

ENTPTR:	BLOCK 1			;Byte pointer to step through entry blocks
CPUPTR:	BLOCK 1			;Directory address of CPU attribute string
OPSPTR:	BLOCK 1			;Op-System
PRTPTR:	BLOCK 1			;Protocols
;Useful subroutines ;⊗ CPOPJ1 CPOPJ PUTCH OUTCH1 PUTSTR PUTST1 PUTDEC PUTOCT PUTOC1 PUTSIX PUTDAT MONTH ERROR

CPOPJ1:	AOS (P)
CPOPJ:	POPJ P,

;Output a character in A, unless H is 0.
PUTCH:	JUMPE H,CPOPJ
	SOSG OBUFH+2
	OUT OCH,
	CAIA
	JRST OUTCH1
	IDPB A,OBUFH+1
	POPJ P,
	
OUTCH1:	OUTSTR [ASCIZ/OUT UUO failed./]
	JRST ERROR

;Output an ASCIZ string with address or byte ptr in B.  Clobbers A and B.
PUTSTR:	TLNN B,-1		;Byte ptr?
	HRLI B,440700		;No, make one
PUTST1:	ILDB A,B		;Get a char
	JUMPE A,CPOPJ		;Return if done
	PUSHJ P,PUTCH		;Output it
	JRST PUTST1

;Output an octal or decimal number in A.  Clobbers A, B, and C.
PUTDEC:	SKIPA C,[=10]
PUTOCT:	MOVEI C,10
PUTOC1:	IDIV A,C
	HRLM B,(P)
	SKIPE A
	PUSHJ P,PUTOC1
	HLRZ A,(P)
	ADDI A,"0"
	JRST PUTCH

;Output a left-adjusted sixbit word in B.  Clobbers A and B.
PUTSIX:	JUMPE B,CPOPJ
	SETZ A,
	LSHC A,6
	ADDI A,40
	PUSHJ P,PUTCH
	JRST PUTSIX

;Output the date in system date format in A.  Clobbers A and B.
PUTDAT:	IDIVI A,=31		;Get day of month - 1 in B
	PUSH P,A		;Save the rest
	MOVEI A,1(B)
	PUSHJ P,PUTDEC
	POP P,A
	IDIVI A,=12		;Get month - 1 in B
	PUSH P,A		;Save the rest
	MOVE B,MONTH(B)		;Get ASCII month
	PUSHJ P,PUTSTR
	POP P,A			;Get year - 1964
	ADDI A,=64
	JRST PUTDEC

MONTH:	[ASCIZ/-Jan-/]
	[ASCIZ/-Feb-/]
	[ASCIZ/-Mar-/]
	[ASCIZ/-Apr-/]
	[ASCIZ/-May-/]
	[ASCIZ/-Jun-/]
	[ASCIZ/-Jul-/]
	[ASCIZ/-Aug-/]
	[ASCIZ/-Sep-/]
	[ASCIZ/-Oct-/]
	[ASCIZ/-Nov-/]
	[ASCIZ/-Dec-/]

ERROR:	OUTSTR [ASCIZ/
Find a wizard./]
	HALT .
;More subroutines ;⊗ OUTADR OUTNAM OUTNLP COMPAR COMPLP COMPL1 COMPL2 CMPLUZ PUTATR PUTALP PUTAT1

;Here to output all addresses for address pointer in A.
OUTADR:	LSH A,-1		;Get PDP-10 address of address block
	ADD A,PUPDIR
	MOVEI X,(A)
	HRLI X,442000		;Byte ptr to beginning of address block
	ILDB A,X		;Get pointer to next address
	PUSH P,A		;Save it
	IBP X			;Skip pointer to owning entry block
	ILDB D,X		;Get address
;Start of code to output IP address as well as Ethernet address
IFE FTETHB,<
	MOVEI B,[ASCIZ/36./]
>;IFE FTETHB
IFN FTETHB,<
	MOVEI B,[ASCIZ/128.12./]
>;IFN FTETHB
	PUSHJ P,PUTSTR
	LDB A,[POINT 8,D,27]	;Get subnet number
	PUSHJ P,PUTDEC
IFE FTETHB,<
	MOVEI B,[ASCIZ/.0./]
	PUSHJ P,PUTSTR
>;IFE FTETHB
IFN FTETHB,<
	MOVEI A,"."
	PUSHJ P,PUTCH
>;IFN FTETHB
	LDB A,[POINT 8,D,35]	;Get host number
	PUSHJ P,PUTDEC
	MOVEI B,[ASCIZ/, /]
	PUSHJ P,PUTSTR
;End of code to output IP address
	MOVEI B,[ASCIZ/SU /]
	PUSHJ P,PUTSTR
	LDB A,[POINT 8,D,27]	;Get subnet number
	PUSHJ P,PUTOCT
	MOVEI A,"#"
	PUSHJ P,PUTCH
	LDB A,[POINT 8,D,35]	;Get host number
	PUSHJ P,PUTOCT
	POP P,C			;Get back next address block pointer
	JUMPE C,CPOPJ		;Zero marks end
	MOVEI B,[ASCIZ/, /]
	PUSHJ P,PUTSTR
	MOVE A,C
	JRST OUTADR		;Print next address

;Here to output all names for name pointer in A.
OUTNAM:	LSH A,-1		;Get PDP-10 address of name block
	ADD A,PUPDIR
	MOVEI X,(A)
	HRLI X,442000		;Byte ptr to beginning of name block
	ILDB A,X		;Get pointer to next name
	PUSH P,A		;Save it
	IBP X			;Skip pointer to owning entry block
	TLC X,3000		;Convert to 8-bit byte ptr
	ILDB B,X		;Get number of bytes in string
OUTNLP:	ILDB A,X		;Get a character
	CAIL A,"a"
	CAILE A,"z"
	CAIA
	SUBI A,"a"-"A"		;Force uppercase
	PUSHJ P,PUTCH		;Output the character
	SOJG B,OUTNLP		;Repeat till done
	POP P,C			;Get back next name block pointer
	JUMPE C,CPOPJ		;Zero marks end
	MOVEI B,[ASCIZ/, /]
	PUSHJ P,PUTSTR
	MOVE A,C
	JRST OUTNAM		;Print next name

;Here to compare an attribute name with a fixed string.
;Call:	MOVE A,<directory address of name>
;	PUSHJ P,COMPAR
;	 ASCIZ/string/
;	 <return here if equal>
;	<return here if not equal>
;Preserves A, B, and C.
COMPAR:	PUSH P,A		;Preserve ACs
	PUSH P,B
	PUSH P,C
	MOVSI C,(<POINT 7,0>)	;Make byte pointer
	HLLM C,-3(P)
	LSH A,-1		;Get PDP-10 address of name string
	ADD A,PUPDIR
	HRLI A,(<POINT 8,0>)	;Make byte pointer
	ILDB B,A		;Get character count
COMPLP:	ILDB C,-3(P)		;Get byte from fixed string
	JUMPE C,COMPL2		;Jump if end of fixed string
	SOJL B,COMPL1		;Jump if end of name string
	ILDB D,A		;Get byte from name string
	CAIN C,(D)		;See if the same
	 JRST COMPLP		;Yes, go back for more if any
	;Here when match fails or name string runs out before fixed string
COMPL1:	ILDB C,-3(P)		;Zap to end of fixed string
	JUMPN C,COMPL1
	JRST CMPLUZ		;Failed
	;Here when at end of fixed string
COMPL2:	SKIPE B			;Both strings ended
CMPLUZ:	AOS -3(P)
	POP P,C			;Restore ACs
	POP P,B
	POP P,A
	JRST CPOPJ1		;Jump over string

;Here to output a string, all uppercased, followed by a colon.
;Call:	MOVE C,<address in directory>
;	PUSHJ P,PUTATR
PUTATR:	MOVEI A,":"		;Print this
	JUMPE C,PUTCH		;If no entry
	MOVEI A," "		;Else start with a space
	PUSHJ P,PUTCH
	LSH C,-1
	ADD C,PUPDIR
	HRLI C,(<POINT 8,0>)	;Make byte ptr
	ILDB B,C		;Get byte count
PUTALP:	SOJL B,PUTAT1		;Return when all done
	ILDB A,C		;Get a byte
	CAIL A,"a"		;Force uppercase
	CAILE A,"z"
	CAIA
	SUBI A,"a"-"A"
	PUSHJ P,PUTCH		;Output the character
	JRST PUTALP		;Back for more
PUTAT1:	MOVEI B,[ASCIZ/ :/]	;End text
	JRST PUTSTR
;Initialization ;⊗ PUPHST

PUPHST:	RESET
	MOVEM 0,DMPNAM		;Save our name
	MOVE P,[IOWD PDLEN,PDL]
	INIT OCH,0		;Open output file in buffer mode
	 SIXBIT/DSK/
	 OBUFH,,0
	 JRST [ OUTSTR [ASCIZ/Output INIT failed./]
		JRST ERROR]
	OUTBUF OCH,BUFNUM	;Get output buffers
	ENTER OCH,HSTBLK
	 JRST [ OUTSTR [ASCIZ/Output ENTER failed./]
		JRST ERROR]
	INIT ICH,17		;Open input file in dump mode
	 SIXBIT/DSK/
	 0			;No buffer headers needed
	 JRST [ OUTSTR [ASCIZ/Input INIT failed./]
		JRST ERROR]
	LOOKUP ICH,PUPBLK
	 JRST [ OUTSTR [ASCIZ/Input LOOKUP failed./]
		JRST ERROR]
	HRRZ A,JOBFF↑		;Place to read in the data
	MOVEM A,PUPDIR
	MOVEI B,-1(A)		;Make IOWD in B
	HLL B,PUPBLK+3
	MOVS C,PUPBLK		;Negative of file size
	SUBI A,1(C)		;Highest location we need
	CORE A,			;Get core for input file
	 JRST [ OUTSTR [ASCIZ/CORE UUO failed./]
		JRST ERROR]
	SETZ C,			;End dump mode command list
	IN ICH,B		;Input the PUP directory
	 JRST PUPIN
	OUTSTR [ASCIZ/Input of PUP directory failed./]
	JRST ERROR
;Main loop ;⊗ PUPIN HDRLP MAINLP ALLDUN

PUPIN:	RELEAS ICH,
	SETO H,			;Enable output
	MOVSI A,-HDRSIZ		;Set up to copy header block
	MOVE B,PUPDIR
	HRLI B,442000		;Byte ptr to beginning of directory
HDRLP:	ILDB C,B		;Get a 16-bit word
	MOVEM C,NUMNAM(A)	;Store it
	AOBJN A,HDRLP
	MOVE A,FSTENT		;First entry block
	LSH A,-1		;Make PDP-10 address
	ADD A,PUPDIR
	HRLI A,442000		;Make byte ptr
	MOVEM A,ENTPTR		;And save it
	;Print date and time and PPN here.
	MOVEI B,[ASCIZ/;Stanford PUP network directory.  Created by /]
	PUSHJ P,PUTSTR
	GETPPN B,
	HRLZ B,B
	PUSHJ P,PUTSIX
	MOVEI B,[ASCIZ/ using PUPHST on /]
	PUSHJ P,PUTSTR
	DATE A,
	PUSHJ P,PUTDAT
	MOVEI B,[ASCIZ/.

NET : SU 0#0 : SU-ETHERNET :

/]
	PUSHJ P,PUTSTR

;Now go through all of the entries
MAINLP:	SOSGE NUMENT		;Count down entry words
	 JRST ALLDUN		;Got 'em all
	ILDB A,ENTPTR		;Pointer to 1st name block
	JUMPE A,ALLDUN		;It might end this way
	PUSH P,A		;Save it
	SOSGE NUMENT		;Count down entry words
	 JRST SHORT
	ILDB A,ENTPTR		;Pointer to 1st address block
	PUSH P,A		;Save it
	;Peek ahead at host number in first address block.  If it's zero,
	;then this isn't a host entry and we don't want to output anything.
	;Also, if the socket number is non-zero, we want to ignore it.
	LSH A,-1		;Get PDP-10 word address
	ADD A,PUPDIR
	LDB H,[POINT 8,1(A),15]	;Host number
	LDB B,[POINT 16,1(A),31];First 16 bits of socket
	LDB C,[POINT 16,2(A),15];Last 16 bits of socket
	SKIPN B			;If either part of socket number is non-zero
	SKIPE C
	SETZ H,			;Then disable output
	;If H is zero, PUTCH (and PUTSTR) will return without outputting anything.
	MOVEI B,[ASCIZ/HOST : /]
	PUSHJ P,PUTSTR
	POP P,A			;Get back address pointer
	PUSHJ P,OUTADR		;Output all addresses
	MOVEI B,[ASCIZ/ : /]
	PUSHJ P,PUTSTR
	POP P,A			;Get back name pointer
	PUSHJ P,OUTNAM		;Output all names
	MOVEI B,[ASCIZ/ :/]
	PUSHJ P,PUTSTR
	SOSGE NUMENT		;Count down entry words
	 JRST SHORT
	ILDB C,ENTPTR		;Get number of attributes
	SETZM CPUPTR		;Zero attribute pointers
	SETZM OPSPTR
	SETZM PRTPTR
ATTLP:	SOJL C,ATTLP1		;Count down attributes
	SOSGE NUMENT		;Count down entry words
	 JRST SHORT
	ILDB A,ENTPTR		;Get attribute name
	SOSGE NUMENT		;Count down entry words
	 JRST SHORT
	ILDB B,ENTPTR		;Get attribute value
	PUSHJ P,COMPAR		;See if it's one of the attributes we want
	 ASCIZ/CPU/
	 MOVEM B,CPUPTR
	PUSHJ P,COMPAR
	 ASCIZ/Op-Sys/
	 MOVEM B,OPSPTR
	PUSHJ P,COMPAR
	 ASCIZ/IP-Protocols/
	 MOVEM B,PRTPTR
	JRST ATTLP		;Back for more
ATTLP1:	IBP ENTPTR		;Bump the pointer, since an entry block is always
				;of odd size, but next block starts on a word
	MOVE C,CPUPTR		;Now put out the attributes in the right order
	PUSHJ P,PUTATR
	MOVE C,OPSPTR
	PUSHJ P,PUTATR
	MOVE C,PRTPTR
	PUSHJ P,PUTATR
	MOVEI B,[ASCIZ/
/]
	PUSHJ P,PUTSTR
	JRST MAINLP		;Continue

ALLDUN:	RELEAS OCH,
	OUTSTR [ASCIZ/Output file compiled successfully./]
	EXIT

SHORT:	OUTSTR [ASCIZ/Inconsistency in input file - ended in middle of entry block/]
	HALT .

	END PUPHST